package com.dbgs.insurance.insuredperson.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.dbgs.insurance.insuredperson.R;
import com.dbgs.insurance.insuredperson.constants.ConstInt;
import com.dbgs.insurance.insuredperson.constants.ConstStr;
import com.dbgs.insurance.insuredperson.utils.TimeCountUtil;
import com.hss.base.BaseActivty;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ModifyPhoneNoActivity extends BaseActivty {
    @BindView(R.id.btn_tite_back)
    Button btnTiteBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_tite_right)
    TextView tvTiteRight;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tv_phone)
    AppCompatTextView tvPhone;
    @BindView(R.id.et_phone_no)
    AppCompatEditText etPhoneNo;
    @BindView(R.id.et_verify_code)
    AppCompatEditText etVerifyCode;
    @BindView(R.id.tv_verify_code)
    AppCompatTextView tvVerifyCode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_phone_no);
        ButterKnife.bind(this);
        initData();
        initView();
        initListener();
    }

    @Override
    public void initView() {
        super.initView();
        tvTitle.setText(R.string.str_modify_phone_no);

        tvTiteRight.setVisibility(View.VISIBLE);
        tvTiteRight.setText(R.string.str_finish);
        tvTiteRight.setTextColor(getResources().getColor(R.color.color_red_txt));
    }

    @OnClick({R.id.btn_tite_back, R.id.tv_tite_right, R.id.tv_verify_code})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_tite_back:
                exit();
                break;
            case R.id.tv_tite_right:
                Intent intent = new Intent();
                intent.putExtra(ConstStr.KEY_VALUE,etPhoneNo.getText());
                setResult(ConstInt.RESULT_VALUE_CHANGED,intent);
                exit();
                break;
            case R.id.tv_verify_code:
                timer.start();
                break;
        }
    }

    CountDownTimer timer = new CountDownTimer(60000,1000) {
        @Override
        public void onTick(long l) {
            tvVerifyCode.setEnabled(false);
            tvVerifyCode.setText((l/1000)+"s后可重发");
        }

        @Override
        public void onFinish() {
            tvVerifyCode.setEnabled(true);
            tvVerifyCode.setText(R.string.str_verify_code);
        }
    };
}
